#ifndef TCP_THREAD_H
#define TCP_THREAD_H
#include <QTcpSocket>
#include <QThread>
#include <QObject>
#include "message.h"
#include <QVariant>
#include <QMutex>

Q_DECLARE_METATYPE(MsgStruct)//注册结构体
class TCP_Thread : public QObject
{
    Q_OBJECT
public:
    explicit TCP_Thread(QObject *parent = nullptr);
    ~TCP_Thread();
    int g_iPreSeq = 0;
    bool g_bTcpStateFlag = false;// TCP状态标志位，false:代表TCP未连接，true:代表TCP已连接

public slots:
    void ConnectToServer(QString ip,qint16 port);
    void CloseTCP();
    void SendMsg(QVariant msg);
    void RecvMsg();

signals:
    void s_recvMsg(QVariant msg);
    void s_wrongMsg(QString title, QString word);
    void s_closeTCPSuccess();
    void s_connectSuccess();
    void s_disconnected();
private:
    QTcpSocket *sockfd = nullptr;

};

#endif // TCP_THREAD_H
